package org.zn.note.jdk.java8.Java8InAction.bean;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @ClassName Transaction
 * @Author zn
 * @Date 2020/1/14 16:24
 **/
public class Transaction {

    private Long transId;
    private String transType = "sale";
    private Long amount;
    private Currency currency;

    private static final Random r = new Random();
    private static final int TRANS_AMOUNT_MAX = 100;

    public Transaction(Long transId, String transType, Currency currency, Long amount) {
        this.transId = transId;
        this.transType = transType;
        this.currency = currency;
        this.amount = amount;
    }

    /**
     * 生成交易：transId顺序递增，金额100以内随机，币种随机
     *
     * @param numbers 交易数量
     * @return
     */
    public static List<Transaction> getTransactioins(int numbers) {
        List<Transaction> l = new ArrayList<>();
        Currency[] currencys = Currency.values();
        for (long i = 1; i <= numbers; i++) {
            l.add(new Transaction(i, randomTransType(), currencys[r.nextInt(currencys.length)], Long.valueOf(r.nextInt(TRANS_AMOUNT_MAX))));
        }
        return l;
    }

    private static String randomTransType() {
        String[] transTypes = {"sale", "query", "auth"};
        return transTypes[r.nextInt(transTypes.length)];
    }

    public Long getTransId() {
        return transId;
    }

    public void setTransId(Long transId) {
        this.transId = transId;
    }

    public String getTransType() {
        return transType;
    }

    public void setTransType(String transType) {
        this.transType = transType;
    }

    public Currency getCurrency() {
        return currency;
    }

    public void setCurrency(Currency currency) {
        this.currency = currency;
    }

    public Long getAmount() {
        return amount;
    }

    public void setAmount(Long amount) {
        this.amount = amount;
    }

    public String toString() {
        return "transId:" + transId + ", transType:" + transType + ", currency:" + currency + ", amount:" + amount;
    }
}
